<!--
 * @Descripttion: 
 * @version: @ 1.0.0
 * @Author: ZJZ
 * @Date: 2021-05-20 16:39:02
 * @LastEditors: 朱江洲
 * @LastEditTime: 2022-05-12 16:41:34
-->

<template>
  <div>
    <el-drawer
      title="批次信息"
      :visible.sync="dialog.dialogDrawerShow"
      :direction="direction"
      :with-header="false"
      size="60%"
      :modal="false"
      @close="drawerClose"
    >
      <div class="head">
        <div class="header">
          <div class="img">
            <img src="@/assets/images/icon-people.png" alt="" />
            <h3>人员信息</h3>
          </div>
          <div class="btn">
            <el-button
              type="primary"
              size="default"
              @click="edit"
              v-hasPermi="['register:staffinformation:edit']"
            >
              编辑
            </el-button>
            <el-button
              type="primary"
              plain
              size="default"
              @click="changeCharge"
              v-hasPermi="['register:staffinformation:replace']"
            >
              更换负责人
            </el-button>
            <el-dropdown>
              <el-button class="el-icon-more"></el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item
                  @click.native="del"
                  v-hasPermi="['register:staffinformation:del']"
                >
                  删除
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
        </div>
        <div class="footer">
          <div class="information">
            <span>姓名</span>
            <h4>{{ drawerData.name }}</h4>
          </div>
          <div class="information">
            <span>公司名称</span>
            <h4>{{ drawerData.companyName }}</h4>
          </div>
          <div class="information">
            <span>部门</span>
            <h4>{{ drawerData.deptName }}</h4>
          </div>
          <div class="information">
            <span>文化程度</span>
            <h4>{{ drawerData.education | onSchool }}</h4>
          </div>
        </div>
      </div>
      <div class="strip"></div>
      <div class="specific">
        <el-tabs
          v-model="activeName"
          type="border-card"
          @tab-click="handleClick"
        >
          <el-tab-pane label="详细资料" name="first">
            <div class="basics">基础信息</div>
            <div class="basics-information">
              <div class="subclass">
                <span>姓名：{{ drawerData.name }}</span>
              </div>
              <div class="subclass">
                <span>手机号码：{{ drawerData.phoneNumber }}</span>
              </div>
              <div class="subclass">
                <span>公司名称：{{ drawerData.companyName }}</span>
              </div>
              <div class="subclass">
                <span>部门：{{ drawerData.deptName }}</span>
              </div>
              <div class="subclass">
                <span>身份证号：{{ drawerData.idNumber }}</span>
              </div>
              <div class="subclass">
                <span>生日：{{ drawerData.birthday }}</span>
              </div>
              <div class="subclass">
                <span>文化程度：{{ drawerData.education | onSchool }}</span>
              </div>
              <div class="subclass">
                <span>工作状态：{{ drawerData.jobState | job }}</span>
              </div>
              <div class="subclass">
                <span>性别：{{ drawerData.sex | gender }}</span>
              </div>
            </div>
            <div class="system">系统信息</div>
            <div class="basics-information">
              <div class="subclass">
                <span>创建人：{{ drawerData.createBy }}</span>
              </div>
              <div class="subclass">
                <span>负责人：{{ drawerData.userName }}</span>
              </div>
              <div class="subclass">
                <span>创建时间：{{ drawerData.createTime }}</span>
              </div>
              <div class="subclass">
                <span>更新时间：{{ drawerData.updateTime }}</span>
              </div>
            </div>
          </el-tab-pane>
          <el-tab-pane label="附件" name="second">
            <el-table
              :data="enclosureData"
              show-header
              :header-cell-style="{ background: '#f2f2f2' }"
            >
              <template slot="empty" class="emptyBg">
                <img src="@/assets/images/empty.jpg" alt="" />
              </template>
              <el-table-column
                label="附件名称"
                prop="fileName"
              ></el-table-column>
              <el-table-column
                label="附件大小"
                prop="fileSize"
              ></el-table-column>
              <el-table-column label="上传人" prop="uploader"></el-table-column>
              <el-table-column
                label="上传时间"
                prop="uploadTime"
              ></el-table-column>
              <el-table-column label="操作">
                <template slot-scope="scope">
                  <span style="color: #1267fa" @click="preview(scope.row)"
                    >预览</span
                  >
                  <span style="margin-left: 10px; color: #1267fa"
                    ><a :href="scope.row.fileId">下载</a></span
                  >
                </template>
              </el-table-column>
            </el-table>
          </el-tab-pane>
          <el-tab-pane label="操作记录" name="third" class="thirdTab">
            <div
              class="operation"
              v-for="(item, index) in Operation"
              :key="index"
            >
              <div class="user">
                <div class="portrait">
                  <img :src="item.avatar" alt="" />
                </div>
                <el-tooltip
                  class="item"
                  effect="dark"
                  :content="item.createBy"
                  placement="top"
                >
                  <div class="name">{{ item.createBy }}</div>
                </el-tooltip>
              </div>
              <div class="record">
                <div class="time">{{ item.createTime }}</div>
                <div class="content">
                  <div>{{ item.content }}</div>
                </div>
              </div>
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>
    </el-drawer>
    <el-dialog title="预览" :visible.sync="show" :fullscreen="true">
      <div v-html="fileHtml" style="text-align: center"></div>
    </el-dialog>
  </div>
</template>

<script>
import { delPerson } from "@/api/registration";
import { perPreview } from "@/api/registration";
import { OperationRecord } from "@/api/currency";
import newStaff from "./newStaff.vue";
export default {
  components: { newStaff },
  props: {
    dialog: {
      type: Object,
      required: true,
    },
    drawerData: {
      type: Object,
      required: true,
    },
  },
  filters: {
    onSchool(val) {
      if (val == 1) {
        return "小学";
      } else if (val == 2) {
        return "初中";
      } else if (val == 3) {
        return "高中/中专";
      } else if (val == 4) {
        return "专科";
      } else if (val == 5) {
        return "大学";
      } else if (val == 6) {
        return "研究生";
      }
    },
    gender(val) {
      if (val == 0) {
        return "男";
      } else if (val == 1) {
        return "女";
      }
    },
    job(val) {
      if (val == 2) {
        return "在职";
      } else if (val == 1) {
        return "离职";
      }
    },
  },
  data() {
    return {
      Operation: [],
      show: false,
      fileHtml: "",
      showForm: false,
      id: 0,
      enclosureData: [],
      activeName: "first",
      direction: "rtl",
      putStaff: {},
    };
  },
  created() {
    this.getRecord();
  },
  methods: {
    // 获取操作记录
    getRecord() {
      OperationRecord({
        columnId: 8,
        entryId: this.drawerData.id,
      }).then((res) => {
        this.Operation = res.data;
      });
    },
    // 预览
    preview(row) {
      perPreview({ url: row.fileId }).then((res) => {
        this.fileHtml = res.msg;
      });
      this.show = true;
    },
    drawerClose() {
      this.enclosureData = [];
      this.dialog.dialogDrawerShowEject = false;
    },
    handleClick(tab, event) {
      if (tab.index == 1) {
        if (
          this.drawerData.fileName !== null &&
          this.drawerData.fileName !== ""
        ) {
          this.enclosureData = [];
          this.enclosureData.push(this.drawerData);
        }
      }
    },
    edit() {
      this.$parent.multipleSelection = [];
      this.$parent.id = this.drawerData.id;
      this.$parent.edit();
    },
    changeCharge() {
      // this.dialog.dialogPerCha = true;
      this.$parent.changeCharge()
      this.$parent.chargeId = this.drawerData.id;
    },
    async del() {
      let arr = [];
      for (let i = 0; i < this.drawerData.length; i++) {
        arr.push(this.multipleSelection[i].id);
      }
      const confirmResult = await this.$confirm(
        "此操作将永久删除该职位, 是否继续?",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      ).catch((err) => err);
      /*如果用户确认打印confirm,如果用户取消显示cancel*/
      if (confirmResult !== "confirm") {
        return this.$message.info("已取消删除!");
      } else {
        let { data: res } = await delPerson(arr);
        this.$parent.getPersonData();
        return this.$message.success("删除成功！");
      }
    },
  },
};
</script>

<style lang="less" scoped>

.head {
  padding: 0 20px;
  width: 100%;
  height: 155px;
  border-bottom: 1px solid #ececec;
  span {
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #999999;
  }
  .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .img {
      img {
        vertical-align: middle;
        margin-right: 12px;
      }
      h3 {
        display: inline-block;
      }
    }
  }
  .footer {
    margin-top: 20px;
    display: flex;
    .information {
      display: flex;
      flex-direction: column;
      margin-right: 80px;
      h4 {
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #2b2b2b;
        margin-top: 12px;
      }
    }
  }
}
.strip {
  width: 100%;
  height: 16px;
  background: #fafafa;
  border: 1px solid #ececec;
  /deep/.el-tabs__nav-scroll {
    background-color: #f5f8fa;
  }
}

/deep/ .el-tab-pane {
  padding-left: 24px;
}
.basics {
  position: relative;
  font-size: 14px;
}
.basics::before {
  content: "";
  position: absolute;
  left: -10px;
  top: 1px;
  width: 3px;
  height: 14px;
  background: #1267fa;
}

.system {
  margin-top: 70px;
  position: relative;
  font-size: 14px;
}
.system::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 1px;
  width: 3px;
  height: 14px;
  background: #1267fa;
}
.basics-information {
  display: flex;
  flex-wrap: wrap;
  .subclass {
    width: 249px;
    margin-top: 30px;
    margin-right: 150px;
    span {
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #999999;
      line-height: 14px;
    }
  }
}
.operation {
  display: flex;
  .user {
    display: flex;
    .portrait {
      width: 30px;
      height: 30px;
      border-radius: 30px;
      img {
        width: 100%;
        height: 100%;
        border-radius: 30px;
      }
    }
    .name {
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      width: 100px;
      height: 30px;
      line-height: 30px;
      margin-left: 14px;
    }
  }
  .record {
    padding-left: 21px;
    margin-left: 44px;
    border-left: 1px dotted #dbdcdb;
    .time {
      font-size: 14px;
      position: relative;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #999999;
      line-height: 14px;
    }
    .time::before {
      content: "";
      position: absolute;
      left: -27px;
      width: 11px;
      height: 11px;
      background-color: #000;
      transform: rotate(45deg);
    }
    .content {
      padding-top: 10px;
      padding-bottom: 10px;
    }
  }
}
.el-dropdown {
  margin-left: 10px;
}
/deep/.thirdTab {
  .el-tabs__content {
    height: 100vh;
  }
}
/deep/.el-table__header-wrapper {
  background: #f2f2f2;
}
</style>